package com.foreveross.pushsdk.main;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

/**
 *
 * @author Huang Li
 * 接收网络状态发生变化的系统广播
 */
public class ConnectivityReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i(PushConfig.LOG_TAG,"Network is changed ");
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		if (PushManager.getInstance().isInited()) {
			if (networkInfo != null && networkInfo.isConnected()) {
				PushManager.getInstance().connect();
			} else {
				PushManager.getInstance().setTryTimesToZero();
				PushManager.getInstance().stopConnect();
			}	
		} 
		
	}
	
}
